package com.emm.yixun.mobile.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.adapter.FromListAdapter;
import com.emm.yixun.mobile.adapter.SingNedListAdapter;
import com.emm.yixun.mobile.adapter.SubscribeListAdapter;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.model.GetPayDepositList;
import com.emm.yixun.mobile.model.GetSignedList;
import com.emm.yixun.mobile.model.GetSubscribeList;
import com.emm.yixun.mobile.ui.customer.NewCustomerActivity;
import com.emm.yixun.mobile.ui.from.FromDetailsActivity;
import com.emm.yixun.mobile.ui.from.NewFromActivity;
import com.emm.yixun.mobile.ui.signed.NewSignedActivity;
import com.emm.yixun.mobile.ui.signed.SigneDetailsdActivity;
import com.emm.yixun.mobile.ui.subscribe.NewSubscribeActivity;
import com.emm.yixun.mobile.ui.subscribe.SubscriDetailsActivity;
import com.eroad.product.tools.PopuContent;
import com.eroad.product.tools.Result;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.util.HashMap;
import java.util.Map;

import cn.swu.pulltorefresh.PullToRefreshSwipeMenuListView;
import cn.swu.pulltorefresh.PullToRefreshSwipeMenuListView.IXListViewListener;
import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;
import xf.tools.Loading;

/**
 * <p>
 * <b>Title：</b> 1 认筹 2认购 3签约
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 *
 * @author tangxin
 * @date 2016年12月6日 下午4:08:55
 */
public class FromListActivity extends SwipeBackActivity implements IXListViewListener {

    private static final String TAG = "FromListActivity";

    /**
     * 客户ID
     */
    private String customerId;

    /**
     * 1 认筹 2认购 3签约
     */
    private int doType = 1;

    /**
     * 签约
     */
    GetSignedList date3 = new GetSignedList();

    PullToRefreshSwipeMenuListView listView_notice;

    /**
     * 客户名
     */
    TextView user_name;

    /**
     * 客户电话
     */
    TextView phone_tel;

    /**
     * 认筹列表适配器
     */
    FromListAdapter fadapter;

    /**
     * 认购列表适配器
     */
    SubscribeListAdapter sadapter;

    /**
     * 签约列表
     */
    SingNedListAdapter singadapter;

    /**
     * 标题
     */
    TextView title_main;

    /**
     * back按钮
     */
    ImageView back_btn;

    /**
     * 新增认筹界面
     */
    ImageView more_btn;

    /**
     * 名称
     */
    private String USERDATA = "";

    /**
     * 电话
     */
    private String USERTEL = "";

    LinearLayout CallPhone_2;

    /**
     * 侧滑关闭框架
     */
    private SwipeBackLayout mSwipeBackLayout;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fromlist_activity);

        SetSwipeBackLayout(mSwipeBackLayout);

        BaseActivity.activity = this;
        doType = getIntent().getIntExtra("Dotype", 1);
        Log.w(TAG, "doType->" + doType);

        customerId = getIntent().getStringExtra("customerId");
        USERDATA = getIntent().getStringExtra("USERDATA");
        USERTEL = getIntent().getStringExtra("USERTEL");

        initView();

        SetRelativiLayoutPadding(R.id.main_head_top_rela);

        initBtn();
        if (doType == 1) {
            getPayDepositList("" + pageNumber, "" + pageSize, 1);
        } else if (doType == 2) {
            GetSubscribeList("" + pageNumber2, "" + pageSize2, 1);
        } else if (doType == 3) {
            GetSignedList("" + pageNumber3, "" + pageSize3, 1);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        BaseActivity.activity = this;
        IntentFilter filter = new IntentFilter(EmmApplication.NEW_ON_CREATE_FROM_LIST);
        registerReceiver(mBroadcastReceiver, filter);
        reLoad();
    }

    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(EmmApplication.NEW_ON_CREATE_FROM_LIST)) {
                reLoad();
            }
        }
    };

    /**
     * <p>
     * <b>Title：</b> 刷新
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:09:16
     */
    private void reLoad() {
        if (doType == 1) {
            getPayDepositList("" + 1, "" + pageSize, 1);
        } else if (doType == 2) {
            GetSubscribeList("" + 1, "" + pageSize2, 1);
        } else if (doType == 3) {
            GetSignedList("" + 1, "" + pageSize3, 1);
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mBroadcastReceiver);
    }

    ;

    /**
     * <p>
     * <b>Title：</b> 初始化view
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:09:22
     */
    private void initView() {
        title_main = (TextView) findViewById(R.id.title_main);
        SetTitle();
        back_btn = (ImageView) findViewById(R.id.back_btn);
        user_name = (TextView) findViewById(R.id.user_name);
        phone_tel = (TextView) findViewById(R.id.phone_tel);
        more_btn = (ImageView) findViewById(R.id.more_btn);
        CallPhone_2 = (LinearLayout) findViewById(R.id.CallPhone_2);
        user_name.setText(USERDATA);
        phone_tel.setText(USERTEL);
        listView_notice = (PullToRefreshSwipeMenuListView) findViewById(R.id.listView_notice);
        listView_notice.setPullRefreshEnable(true);
        listView_notice.setPullLoadEnable(true);
        listView_notice.setXListViewListener(this);
        listView_notice.setRefreshTime(EmmApplication.getData("RefreshTime_fromlist"));
    }

    /**
     * <p>
     * <b>Title：</b> 初始化监听事件
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:10:14
     */
    private void initBtn() {
        CallPhone_2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (phone_tel.getText().toString() == null || "".equals(phone_tel.getText().toString())
                        || TextUtils.isEmpty(phone_tel.getText().toString())) {
                    return;
                }
                EmmApplication.callPhone(phone_tel.getText().toString(), customerId);
            }
        });
        back_btn.setVisibility(View.VISIBLE);
        back_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        String isShowMoreBtn = "";

        if (doType == 1) {
            isShowMoreBtn = EmmApplication.getData(EmmApplication.isAddPaydeposit);
        } else if (doType == 2) {
            isShowMoreBtn = EmmApplication.getData(EmmApplication.isAddSubscribe);
        } else if (doType == 3) {
            isShowMoreBtn = EmmApplication.getData(EmmApplication.isAddSigned);
        }

        more_btn.setVisibility("1".equals(isShowMoreBtn) ? View.VISIBLE : View.GONE);
        more_btn.setImageResource(R.drawable.icon_jia);
        more_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if (EmmApplication.IsLoadingFromList) {
                    Log.v(TAG, "正在加载新界面，该次点击无效");
                    return;
                }

                Intent intent = new Intent();
                intent.putExtra("customerId", customerId);
                if (doType == 1) {
                    // 新增认筹
                    EmmApplication.IsLoadingFromList = true;
                    intent.setClass(FromListActivity.this, NewFromActivity.class);
                    startActivity(intent);
                } else if (doType == 2) {
                    // 新增认购
                    EmmApplication.IsLoadingFromList = true;
                    intent.putExtra("OpenType", "1");
                    intent.setClass(FromListActivity.this, NewSubscribeActivity.class);
                    startActivity(intent);
                } else if (doType == 3) {
                    // 新增签约
                    EmmApplication.IsLoadingFromList = true;
                    intent.putExtra("OpenType", "1");
                    intent.setClass(FromListActivity.this, NewSignedActivity.class);
                    startActivity(intent);
                }
            }
        });
        listView_notice.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0) {// 不处理

                } else {// 否则减去头部占用的一个位置

                    if (EmmApplication.IsLoadingFromList) {
                        Log.v(TAG, "正在加载新界面，该次点击无效");
                        return;
                    }
                    EmmApplication.IsLoadingFromList = true;

                    position--;
                    Intent intent = new Intent();
                    intent.putExtra("customerId", customerId);
                    if (doType == 1) {
                        // 认筹详情
                        pageNumber = 1;
                        intent.setClass(FromListActivity.this, FromDetailsActivity.class);
                        intent.putExtra("payDepositId",
                                getpaydepos.getPayDepositList().get(position).getPayDepositId());
                    } else if (doType == 2) {
                        // 认购详情
                        pageNumber2 = 1;
                        intent.setClass(FromListActivity.this, SubscriDetailsActivity.class);
                        intent.putExtra("subscribeId", getSubscribe.getSubscribeList().get(position).getSubscribeId());
                    } else if (doType == 3) {
                        // 签约详情
                        pageNumber3 = 1;
                        intent.setClass(FromListActivity.this, SigneDetailsdActivity.class);
                        intent.putExtra("signId", getsigned.getSignedList().get(position).getSignedId());
                    }
                    startActivity(intent);
                }
            }
        });
    }

    /**
     * <p>
     * <b>Title：</b> 判断显示标题
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:16:55
     */
    private void SetTitle() {
        if (doType == 1) {
            title_main.setText(getString(R.string.dotype1));
        } else if (doType == 2) {
            title_main.setText(getString(R.string.dotype2));
        } else if (doType == 3) {
            title_main.setText(getString(R.string.dotype3));
        }
    }

    /**
     * 刷新
     */
    @Override
    public void onRefresh() {
        listView_notice.stopLoadMore();
        h.sendEmptyMessage(1);
    }

    /**
     * 加载更多
     */
    @Override
    public void onLoadMore() {
        listView_notice.stopRefresh();
        h.sendEmptyMessage(2);
    }

    Handler h = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 1) {
                if (doType == 1) {
                    pageNumber = 1;
                    getPayDepositList("" + 1, "" + pageSize, 1);
                } else if (doType == 2) {
                    pageNumber2 = 1;
                    GetSubscribeList("" + 1, "" + pageSize2, 1);
                } else if (doType == 3) {
                    pageNumber3 = 1;
                    GetSignedList("" + 1, "" + pageSize3, 1);
                }
            } else if (msg.what == 2) {
                if (doType == 1) {
                    pageNumber++;
                    getPayDepositList("" + pageNumber, "" + pageSize, 2);
                } else if (doType == 2) {
                    pageNumber2++;
                    GetSubscribeList("" + pageNumber2, "" + pageSize2, 2);
                } else if (doType == 3) {
                    pageNumber3++;
                    GetSignedList("" + pageNumber3, "" + pageSize3, 2);
                }
            }
        }
    };

    /**
     * 客户列表
     */
    GetPayDepositList getpaydepos;

    /**
     * 页码
     */
    int pageNumber = 1;

    /**
     * 页码条数
     */
    int pageSize = 10;

    boolean IsLoading = true;

    /**
     * <p>
     * <b>Title：</b>认筹列表
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param pageNumberd
     * @param pageSized
     * @param opentype
     * @author tangxin
     * @date 2016年12月7日 下午3:17:22
     */
    private void getPayDepositList(String pageNumberd, String pageSized, final int opentype) {
        EmmApplication.updateUrl("getPayDepositList");
        Map<String, String> map = new HashMap<String, String>();

        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("pageNumber", pageNumberd);
        map.put("pageSize", pageSized);
        map.put("customerId", customerId);

        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v(TAG, "getPayDepositList-->post:" + EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
                listView_notice.stopRefresh();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                listView_notice.setRefreshTime(timed);
                EmmApplication.setData("RefreshTime_fromlist", timed);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                listView_notice.stopRefresh();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                listView_notice.setRefreshTime(timed);
                EmmApplication.setData("RefreshTime_fromlist", timed);
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.hideDialogForLoading();
                if (opentype == 1) {
                    Loading.showDialogForLoading(FromListActivity.this, "正在加载...", false, true, 60000);
                }
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                GetPayDepositList getcust = JSONObject.parseObject(resData.toString(), GetPayDepositList.class);
                if ("1".equals(getcust.getResult())) {
                    Log.v("获取成功", "");
                    try {
                        user_name.setText(getcust.getCustomerName());
                        phone_tel.setText(getcust.getCustomerPhone());
                    } catch (NullPointerException e) {
                    }
                    if (getcust.getPayDepositList() != null) {
                        if (opentype == 1) {// 刷新
                            getpaydepos = new GetPayDepositList();
                            getpaydepos = getcust;
                        } else {// 加载
                            if (getpaydepos != null) {
                                // getpaydepos.setPayDepositList(getcust.getPayDepositList());
                                getpaydepos.getPayDepositList().addAll(getcust.getPayDepositList());
                            } else {
                                getpaydepos = new GetPayDepositList();
                                getpaydepos.getPayDepositList().addAll(getcust.getPayDepositList());
                            }
                        }
                        if (getpaydepos.getPayDepositList().size() < (pageNumber * pageSize)) {// 代表没有更多
                            IsLoading = false;
                            // EmmApplication.T("没有更多客户");
                        }
                        if (fadapter == null) {
                            fadapter = new FromListAdapter(FromListActivity.this, getpaydepos);
                            listView_notice.setAdapter(fadapter);
                        } else {
                            fadapter.SetDate(getpaydepos);
                        }
                    } else {
                        if (pageNumber > 0 && opentype != 1)
                            pageNumber--;
                        listView_notice.stopLoadMore();
                        listView_notice.stopRefresh();
                        if (opentype == 2) {

                        } else {
                            if (getpaydepos != null && getpaydepos.getPayDepositList() != null) {
                                getpaydepos.getPayDepositList().clear();
                            } else {
                                getpaydepos = new GetPayDepositList();
                            }
                            if (fadapter == null) {
                                fadapter = new FromListAdapter(FromListActivity.this, getpaydepos);
                                listView_notice.setAdapter(fadapter);
                            } else {
                                fadapter.SetDate(getpaydepos);
                            }
                        }
                    }
                } else {
                    EmmApplication.T(getcust.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + getcust.getErrorCode().toString() + "errorMsg:"
                                + getcust.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("客户列表，错误信息获取空指针异常", "");
                    }
                }
            }
        });
    }

    GetSubscribeList getSubscribe;

    /**
     * 页码
     */
    int pageNumber2 = 1;

    /**
     * 页码条数
     */
    int pageSize2 = 10;

    boolean IsLoading2 = true;

    /**
     * <p>
     * <b>Title：</b> 认购列表
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param pageNumber2s
     * @param pageSize2s
     * @param opentype
     * @author tangxin
     * @date 2016年12月7日 下午3:19:44
     */
    private void GetSubscribeList(String pageNumber2s, String pageSize2s, final int opentype) {
        EmmApplication.updateUrl("getSubscribeList");
        Map<String, String> map = new HashMap<String, String>();

        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("pageNumber", pageNumber2s);
        map.put("pageSize", pageSize2s);
        map.put("customerId", customerId);

        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getSubscribeList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
                listView_notice.stopRefresh();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                listView_notice.setRefreshTime(timed);
                EmmApplication.setData("RefreshTime_fromlist", timed);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                listView_notice.stopRefresh();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                listView_notice.setRefreshTime(timed);
                EmmApplication.setData("RefreshTime_fromlist", timed);
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.hideDialogForLoading();
                if (opentype == 1) {
                    Loading.showDialogForLoading(FromListActivity.this, "正在加载...", false, true, 60000);
                }
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                GetSubscribeList getcust = JSONObject.parseObject(resData.toString(), GetSubscribeList.class);
                if ("1".equals(getcust.getResult())) {
                    Log.v("获取成功", "");
                    try {
                        user_name.setText(getcust.getCustomerName());
                        phone_tel.setText(getcust.getCustomerPhone());
                    } catch (NullPointerException e) {
                    }
                    if (getcust.getSubscribeList() != null) {
                        if (opentype == 1) {// 刷新
                            getSubscribe = new GetSubscribeList();
                            getSubscribe = getcust;
                        } else {// 加载
                            if (getSubscribe != null) {
                                getSubscribe.getSubscribeList().addAll(getcust.getSubscribeList());
                            } else {
                                getSubscribe = new GetSubscribeList();
                                getSubscribe.getSubscribeList().addAll(getcust.getSubscribeList());
                            }
                        }
                        if (getSubscribe.getSubscribeList().size() < (pageNumber2 * pageSize2)) {// 代表没有更多
                            IsLoading2 = false;
                        }
                        if (sadapter == null) {
                            sadapter = new SubscribeListAdapter(FromListActivity.this, getSubscribe);
                            listView_notice.setAdapter(sadapter);
                        } else {
                            sadapter.SetDate(getSubscribe);
                        }
                    } else {
                        if (pageNumber2 > 0 && opentype != 1)
                            pageNumber2--;
                        listView_notice.stopLoadMore();
                        listView_notice.stopRefresh();
                        if (opentype == 2) {

                        } else {
                            if (getSubscribe != null && getSubscribe.getSubscribeList() != null) {
                                getSubscribe.getSubscribeList().clear();
                            } else {
                                getSubscribe = new GetSubscribeList();
                                if (sadapter == null) {
                                    sadapter = new SubscribeListAdapter(FromListActivity.this, getSubscribe);
                                    listView_notice.setAdapter(sadapter);
                                } else {
                                    sadapter.SetDate(getSubscribe);
                                }
                            }
                        }
                    }
                } else {
                    EmmApplication.T(getcust.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + getcust.getErrorCode().toString() + "errorMsg:"
                                + getcust.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("客户列表，错误信息获取空指针异常", "");
                    }
                }
            }
        });
    }

    GetSignedList getsigned;

    /**
     * 页码
     */
    int pageNumber3 = 1;

    /**
     * 页码条数
     */
    int pageSize3 = 10;

    boolean IsLoading3 = true;

    /**
     * <p>
     * <b>Title：</b> 签约列表
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @param pageNumber3s
     * @param pageSize3s
     * @param opentype3
     * @author tangxin
     * @date 2016年12月7日 下午3:20:32
     */
    private void GetSignedList(String pageNumber3s, String pageSize3s, final int opentype3) {
        EmmApplication.updateUrl("getSignedList");
        Map<String, String> map = new HashMap<String, String>();

        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("pageNumber", pageNumber3s);
        map.put("pageSize", pageSize3s);
        map.put("customerId", customerId);

        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getSignedList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
                listView_notice.stopRefresh();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                listView_notice.setRefreshTime(timed);
                EmmApplication.setData("RefreshTime_fromlist", timed);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                listView_notice.stopRefresh();
                String timed = EmmApplication.dataTime(EmmApplication.geTime(), "yyyy-MM-dd HH:mm");
                listView_notice.setRefreshTime(timed);
                EmmApplication.setData("RefreshTime_fromlist", timed);
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                if (opentype3 == 1) {
                    Loading.showDialogForLoading(FromListActivity.this, "正在加载...", false, true, 60000);
                }
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v("content", content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                GetSignedList getcust = JSONObject.parseObject(resData.toString(), GetSignedList.class);
                if ("1".equals(getcust.getResult())) {
                    Log.v("获取成功", "");
                    try {
                        if ("".equals(getcust.getCustomerName()) || TextUtils.isEmpty(getcust.getCustomerName())) {
                            Log.v(TAG, "名称为空");
                        } else {
                            user_name.setText(getcust.getCustomerName());
                        }
                        if ("".equals(getcust.getCustomerPhone()) || TextUtils.isEmpty(getcust.getCustomerPhone())) {
                            Log.v(TAG, "号码");
                        } else {
                            phone_tel.setText(getcust.getCustomerPhone());
                        }
                    } catch (NullPointerException e) {
                    }
                    if (getcust.getSignedList() != null) {
                        if (opentype3 == 1) {// 刷新
                            getsigned = new GetSignedList();
                            getsigned = getcust;
                        } else {// 加载
                            if (getsigned != null) {
                                getsigned.getSignedList().addAll(getcust.getSignedList());
                            } else {
                                getsigned = new GetSignedList();
                                getsigned.getSignedList().addAll(getcust.getSignedList());
                            }
                        }
                        if (getsigned.getSignedList().size() < (pageNumber3 * pageSize3)) {// 代表没有更多
                            IsLoading3 = false;
                        }
                        if (fadapter == null) {
                            singadapter = new SingNedListAdapter(FromListActivity.this, getsigned);
                            listView_notice.setAdapter(singadapter);
                        } else {
                            singadapter.SetData(getsigned);
                        }
                    } else {
                        if (pageNumber3 > 0 && opentype3 != 1)
                            pageNumber3--;
                        listView_notice.stopLoadMore();
                        listView_notice.stopRefresh();
                        if (opentype3 == 2) {

                        } else {
                            if (getsigned != null && getsigned.getSignedList() != null) {
                                getsigned.getSignedList().clear();
                            } else {
                                getsigned = new GetSignedList();
                                if (singadapter == null) {
                                    singadapter = new SingNedListAdapter(FromListActivity.this, getsigned);
                                    listView_notice.setAdapter(singadapter);
                                } else {
                                    singadapter.SetData(getsigned);
                                }
                            }
                        }
                    }
                } else {
                    EmmApplication.T(getcust.getErrorMsg().toString());
                    try {
                        Log.v("获取失败", "errorCode:" + getcust.getErrorCode().toString() + "errorMsg:"
                                + getcust.getErrorMsg().toString());
                    } catch (NullPointerException e) {
                        Log.v("客户列表，错误信息获取空指针异常", "");
                    }
                }
            }
        });
    }

}
